﻿@{
    ViewBag.Title = "重置密码";
}
@section css{
    <style type="text/css">
        #getpwdcontent {
            min-height: 400px;
        }

        #getpwdfrm input, #getpwdfrm textarea, #getpwdfrm button, #getpwdfrm span {
            border-radius: 0px;
        }

        #getpwdfrm fieldset legend {
            font-size:x-large;
        }

        .form-item {
            margin-top: 50px;
        }

        #verifycode_img {
            cursor: pointer;
            height: 25px;
            width: 60px;
            padding-left: 5px;
            padding-bottom: 7px;
        }
    </style>
}
<div class="container-fluid" id="getpwdcontent">
    <div class="row-fluid">
        <div class="span12">
            <div class="row-fluid">
                <div class="span8">
                    <form id="getpwdfrm">
                        <fieldset>
                            <legend>重置密码</legend>
                            @Html.AntiForgeryToken()
                            <div class="control-group  form-item">
                                <label class="control-label" for="newpassword">新密码</label>
                                <div class="controls">
                                    <input type="password" class="input-large" name="newpassword" id="newpassword">
                                </div>
                            </div>
                            <div class="control-group  form-item">
                                <label class="control-label" for="confirmnewpassword">确认新密码</label>
                                <div class="controls">
                                    <input type="password" class="input-large" name="confirmnewpassword" id="confirmnewpassword">
                                </div>
                            </div>
                               <div class="control-group form-item">
                                <label class="control-label" for="verifycode">验证码</label>
                                <div class="controls">
                                    <input type="text" autocomplete="off" class="input-large" name="verifycode" id="verifycode">
                                    <img src="/VerificationCode/Index" id="verifycode_img" />
                                </div>
                            </div>
                            <div class="control-group">
                                <div class="controls">
                                    <button type="submit" class="btn">提交</button>
                                    <img src="~/Images/loading.gif" id="loding" style="display: none" />
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
                <div class="span4">
                </div>
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.form.js"></script>
    <script type="text/javascript">

        $(function () {
            $("#info").css({ display: "none" });
            $("#verifycode_img").click(function () {
                showverifycode();
            });

            function showverifycode() {
                var numkey = Math.random() + (new Date().getDate());
                document.getElementById("verifycode_img").src = "/VerificationCode/Index?NumKey=" + numkey;
            }
        })

        jQuery.validator.addMethod("password", function (value, element) {
            var val = /^[\w]{6,15}$/;
            return this.optional(element) || (val.test(value));
        }, "密码为6到15位,由字母数字下划线组成");

        $("#getpwdfrm").validate({
            errorClass: "help-inline",
            rules: {
                newpassword: {
                    required: true,
                    minlength: 6,
                    password: true
                },
                confirmnewpassword: {
                    required: true,
                    equalTo: "#newpassword"
                },
                verifycode: {
                    required: true
                }
            },
            messages: {
                newpassword: {
                    required: "新密码为空",
                    minlength: "密码最小长度为6位"
                },
                confirmnewpassword: {
                    required: "确认密码为空",
                    equalTo: "两次输入密码不一致不一致"
                },
                verifycode: {
                    required: "验证码为空"
                }
            },
            highlight: function (element) {
                $(element).closest('.control-group').removeClass('success').addClass('error');
            },
            success: function (element) {
                element
				.text('OK!').addClass('valid')
				.closest('.control-group').removeClass('error').addClass('success');
            }
        });

        $('#getpwdfrm').on('submit', function (e) {
            e.preventDefault();
            if ($("#getpwdfrm").valid()) {
                $(this).ajaxSubmit({
                    type: "post",
                    url: "/Account/GetPassWord?UID=@ViewBag.UID",
                    beforeSend: function () {
                        $("#loding").show();
                    },
                    success: function (msg) {
                        $("#loding").hide();
                        if (msg.Result == "OK") {
                            alert("重置密码成功！")
                            window.location.href="/Account/Login";
                        } else {
                            alert(msg.Message);
                        }
                    }
                });
            }
        });
    </script>
}
